package com.cls.business.service.impl;

import com.cls.business.entity.DeclarePlan;
import com.cls.business.service.IDeclarePlanService;
import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.EntrustCheckLog;
import com.cls.business.mapper.EntrustCheckLogMapper;
import com.cls.business.service.IEntrustCheckLogService;
import com.cls.common.utils.StringUtils;
import com.cls.system.service.IConfigureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
import java.util.List;

/**
 * 委托课题审核记录表 Service实现
 *
 * @author slx
 * @date 2020-12-04 15:46:13
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EntrustCheckLogServiceImpl extends ServiceImpl<EntrustCheckLogMapper, EntrustCheckLog> implements IEntrustCheckLogService {
    @Autowired
    private IDeclarePlanService declarePlanService;
    @Override
    public PageInfo<EntrustCheckLog> findEntrustCheckLogs(QueryRequest request, EntrustCheckLog entrustCheckLog) {
        LambdaQueryWrapper<EntrustCheckLog> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        if(entrustCheckLog.getDeclareId()!=null){
            queryWrapper.eq(EntrustCheckLog::getDeclareId,entrustCheckLog.getDeclareId());
        }
        if(StringUtils.isNotBlank(entrustCheckLog.getCheckType())){
            queryWrapper.eq(EntrustCheckLog::getCheckType,entrustCheckLog.getCheckType());
        }
        queryWrapper.orderByDesc(EntrustCheckLog::getCreateTime);
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<EntrustCheckLog> list= this.list(queryWrapper);
       /* list.forEach(item->{
            if(item.getDeclarePlanId()!=null){
                DeclarePlan byId = declarePlanService.getById(item.getDeclarePlanId());
                item.setDeclarePlan(byId);
            }
        });*/
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<EntrustCheckLog> findEntrustCheckLogs(EntrustCheckLog entrustCheckLog) {
	    LambdaQueryWrapper<EntrustCheckLog> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
        if(entrustCheckLog.getDeclareId()!=null){
            queryWrapper.eq(EntrustCheckLog::getDeclareId,entrustCheckLog.getDeclareId());
        }
        if(entrustCheckLog.getCheckType()!=null){
            queryWrapper.eq(EntrustCheckLog::getCheckType,entrustCheckLog.getCheckType());
        }
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createEntrustCheckLog(EntrustCheckLog entrustCheckLog) {
        this.save(entrustCheckLog);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateEntrustCheckLog(EntrustCheckLog entrustCheckLog) {
        this.saveOrUpdate(entrustCheckLog);
    }


    /**
    * 删除
    * @param ids
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteEntrustCheckLogs(String[] ids) {
        List< String > list = Arrays.asList(ids);
        this.removeByIds(list);
     }

}
